package com.example.host.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.host.domain.SessionInfo;
import com.example.host.utils.SessionInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MqttController {
    @Autowired
    SessionInfoUtils sessionInfoUtils;

    @PostMapping("/mqtt/mqttInstallResponse")
    public String mqttInstallResponse(@RequestBody JSONObject jsonObject){
        sessionInfoUtils.insertOrReplaceSessionInfo(jsonObject);
        return "会话信息发送成功！";
    }

    @PostMapping("/mqtt/mqttUninstallResponse")
    public String mqttUninstallResponse(@RequestBody JSONObject jsonObject){
        sessionInfoUtils.updateMsg(jsonObject);
        System.out.println(SessionInfo.sessionList);
        sessionInfoUtils.deleteSessionInfo(jsonObject.getString("deviceName"));
        return "信息发送成功！";
    }
}
